package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.entity.DigitalCollectionProductInfo;
import com.sc.nft.entity.vo.AddCdkActivityVO;
import com.sc.nft.entity.vo.PageCdkVO;
import com.sc.nft.entity.vo.ProductCdkVO;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.ProductCdk;
import com.sc.nft.mapper.ProductCdkMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;

/**
 * (sc_product_cdk)数据DAO
 *
 * @author Sun
 * @since 2022-08-22 16:34:32
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class ProductCdkDao extends ServiceImpl<ProductCdkMapper, ProductCdk> {

    public List<ProductCdk> getOneByProductId(DigitalCollectionProductInfo productInfo) {
        LambdaQueryWrapper<ProductCdk> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ProductCdk::getProductId,productInfo);
        return list(wrapper);
    }

    public List<ProductCdk> getListByList(HashSet<String> cdks) {
       return baseMapper.getListByList(cdks);
    }

    public ProductCdk getOneByCdk(String cdk) {
        LambdaQueryWrapper<ProductCdk> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ProductCdk::getCdk,cdk);
        return getOne(wrapper);
    }

    public HashSet<String> getListByIsUse() {
        return baseMapper.getListByIsUse();
    }

    public List<ProductCdk> getListByProduct(Long productId) {
        LambdaQueryWrapper<ProductCdk> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ProductCdk::getProductId,productId);
        return list(wrapper);
    }

    public List<ProductCdkVO> getCdkListByProduct(Long productId) {
        return baseMapper.getCdkListByProduct(productId);
    }

    public Page<ProductCdkVO> getPageCdkList(Long productId, int pageNo, int pageSize) {
        return baseMapper.getPageCdkList(productId,new Page(pageNo,pageSize));
    }

    /**
     * 查询CDK活动
     * @param page
     * @param cdkActivityId
     * @param cdk
     * @param isUse
     * @param isExpired
     * @return
     */
    public Page<PageCdkVO> getPageCdk(Page page, Long cdkActivityId, String cdk, Integer isUse, Integer isExpired) {
        if(page.getSize()>50){
            page.setSize(-1);
        }
        return baseMapper.getPageCdk(page,cdkActivityId,cdk,isUse,isExpired);
    }

    public Integer getCountByCdkActivityId(Long cdkActivityId) {
        LambdaQueryWrapper<ProductCdk> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ProductCdk::getCdkActivityId,cdkActivityId);
        return count(wrapper);
    }

    public Integer getListByProductIdList(List<Long> productIdList) {
        return baseMapper.getListByProductIdList(productIdList);
    }

    /**
     * 获取自定义生成的CDK一条记录
     * @param cdkActivityId
     * @param pageNo
     * @param pageSize
     * @return
     */
    public Page<PageCdkVO> getPageCustomCdk(Long cdkActivityId, Integer pageNo, Integer pageSize) {
        return baseMapper.getPageCustomCdk(cdkActivityId,new Page(pageNo,pageSize));
    }
}